package com.blog.service.impl;

import com.blog.dao.DiaryDao;
import com.blog.dao.NodeDao;
import com.blog.pojo.Comment;
import com.blog.pojo.Diary;
import com.blog.service.DiaryService;
import com.blog.utils.FindRequestCacheUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

@Service("diaryService")
public class DiaryServiceImpl implements DiaryService {

    @Resource(name = "diaryDao")
    private DiaryDao diaryDao;

    @Autowired
    private FindRequestCacheUtil cacheUtil;

    @Override
    public ArrayList<HashMap<String,String>> findDiaryMotto() {
        return diaryDao.findDiaryMotto();
    }

    @Override
    public int findDiaryCount(String createTime) {
        return diaryDao.findDiaryCount(createTime);
    }

    @Override
    public ArrayList<Diary> findDiary(int currentPage,String createTime) {
        int startIndex = (currentPage - 1) * 10;
        ArrayList<Diary> diarys = diaryDao.findDiary(startIndex, createTime);
        for (Diary d : diarys) {
            int count = diaryDao.findDiaryCommentCountById(d.getId());
            d.setCommentCount(count);
        }
        return diarys;
    }

    @Override
    public List<Comment> findDiaryComment(int id) {
        return diaryDao.findDiaryComment(id);
    }

    @Override
    public void addComment(int id , Comment comment) {
        diaryDao.addComment(id , comment);
    }

    @Override
    public void addDiary(Diary diary) {
        diaryDao.addDiary(diary);
    }
}
